package bcrypt

import (
	"golang.org/x/crypto/bcrypt"
	"log"
)

// EncodePassword 密码加密
func EncodePassword(password string) string {
	encodePassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		log.Panicln("密码加密失败！")
	}
	return string(encodePassword)
}

// PasswordCompare 密码校验
func PasswordCompare(encryption, password string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(encryption), []byte(password))

	if err != nil {
		return false
	}
	return true
}
